package com.zhenmaitang.clinic_sys.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.zhenmaitang.clinic_sys.dto.GetMenuListRequest;
import com.zhenmaitang.clinic_sys.entity.SysMenu;
import com.zhenmaitang.clinic_sys.service.MenuService;
import com.zhenmaitang.clinic_sys.util.ApiResponse;

import io.swagger.v3.oas.annotations.tags.Tag;

@RestController
@RequestMapping("/api/menu")
@CrossOrigin(origins = "*")
@Tag(name = "菜单管理", description = "菜单管理相关接口")
public class MenuController {

    private static final Logger logger = LoggerFactory.getLogger(MenuController.class);
    
    @Autowired
    private MenuService menuService;

    @PostMapping("/list")
    @Tag(name = "获取菜单列表", description = "获取系统菜单列表")
    public ApiResponse<List<SysMenu>> getMenuList(@Valid @RequestBody GetMenuListRequest request) {
        logger.debug("Received menu list request with roles: {}", request.getRolenames());
        
        //从 request 获取角色
        List<SysMenu> menuList = menuService.getRoleMenus(request.getRolenames());
        
        return ApiResponse.success(menuList);
    }

    
}